/*初始化数据表格*/
function initTable() {
    var url=getBasePath()+'/mdm/company/getListData.json';
    var tableId="table_data";
    $("#"+tableId).dataTable().fnDestroy();
    json = {};
    json.showLineNuber = false;
    json.id = tableId;
    json.pagesize=10;
    json.url = url ;
    json.param = [
        {"name": "id", "value": $.trim($("#id").val())},
        {"name": "companyCode", "value": $.trim($("#companyCode").val())},
        {"name": "companyName", "value": $.trim($("#companyName").val())},
        {"name": "companyType", "value": $.trim($("#companyType").val())},
        {"name": "companyShortName", "value": $.trim($("#companyShortName").val())},
        {"name": "companyProp", "value": $.trim($("#companyProp").val())},
        {"name": "parentId", "value": $.trim($("#parentId").val())},
        {"name": "companyIndustry", "value": $.trim($("#companyIndustry").val())},
        {"name": "licenseNo", "value": $.trim($("#licenseNo").val())},
        {"name": "licenseNoImg", "value": $.trim($("#licenseNoImg").val())},
        {"name": "taxNo", "value": $.trim($("#taxNo").val())},
        {"name": "ajCompanyClass", "value": $.trim($("#ajCompanyClass").val())},
        {"name": "corporation", "value": $.trim($("#corporation").val())},
        {"name": "ceo", "value": $.trim($("#ceo").val())},
        {"name": "ceoIdcard", "value": $.trim($("#ceoIdcard").val())},
        {"name": "ceoMobile", "value": $.trim($("#ceoMobile").val())},
        {"name": "ceoIdcardAttachA", "value": $.trim($("#ceoIdcardAttachA").val())},
        {"name": "ceoIdcardAttachB", "value": $.trim($("#ceoIdcardAttachB").val())},
        {"name": "certificateStatus", "value": $.trim($("#certificateStatus").val())},
        {"name": "certificateTime", "value": $.trim($("#certificateTime").val())},
        {"name": "certificatedTime", "value": $.trim($("#certificatedTime").val())},
        {"name": "status", "value": $.trim($("#status").val())},
        {"name": "countryCode", "value": $.trim($("#countryCode").val())},
        {"name": "provinceCode", "value": $.trim($("#provinceCode").val())},
        {"name": "cityCode", "value": $.trim($("#cityCode").val())},
        {"name": "countyCode", "value": $.trim($("#countyCode").val())},
        {"name": "postcode", "value": $.trim($("#postcode").val())},
        {"name": "street", "value": $.trim($("#street").val())},
        {"name": "address", "value": $.trim($("#address").val())},
        {"name": "bankName", "value": $.trim($("#bankName").val())},
        {"name": "bankAccount", "value": $.trim($("#bankAccount").val())},
        {"name": "remark", "value": $.trim($("#remark").val())},
    ];
    json.columns = [
        {
            "mData": "companyCode", "sWidth": "15%", "sClass": "text-center",
            "mRender": function (data, type, row) {
                if (data) {
					var detailStr="<a class='icondatatable' vb='详情' href=\"#\" onclick='toDetailPage(\""+data+"\");'><i class=\"icon-detail\"></i></a>";
                    var editStr="<a class='icondatatable' vb='修改' href=\"#\" onclick='toEditCompany(\""+data+"\");'><i class=\"icon-edit\"></i></a>";
                    var delStr="<a class='icondatatable' vb='删除' href=\"#\"  onclick='deleteCompany(\""+data+"\");'><i class=\"icon-bin\"></i></a>";

                    return detailStr+editStr+delStr;
                }
            }
        },
        {"mData": "id", "sClass": "text-center"},
        {"mData": "companyCode", "sClass": "text-center"},
        {"mData": "companyName", "sClass": "text-center"},
        {"mData": "companyType", "sClass": "text-center"},
        {"mData": "companyShortName", "sClass": "text-center"},
        {"mData": "companyProp", "sClass": "text-center"},
        {"mData": "parentId", "sClass": "text-center"},
        {"mData": "companyIndustry", "sClass": "text-center"},
        {"mData": "licenseNo", "sClass": "text-center"},
        {"mData": "licenseNoImg", "sClass": "text-center"},
        {"mData": "taxNo", "sClass": "text-center"},
        {"mData": "ajCompanyClass", "sClass": "text-center"},
        {"mData": "corporation", "sClass": "text-center"},
        {"mData": "ceo", "sClass": "text-center"},
        {"mData": "ceoIdcard", "sClass": "text-center"},
        {"mData": "ceoMobile", "sClass": "text-center"},
        {"mData": "ceoIdcardAttachA", "sClass": "text-center"},
        {"mData": "ceoIdcardAttachB", "sClass": "text-center"},
        {"mData": "certificateStatus", "sClass": "text-center"},
        {"mData": "certificateTime", "sClass": "text-center"},
        {"mData": "certificatedTime", "sClass": "text-center"},
        {"mData": "status", "sClass": "text-center"},
        {"mData": "countryCode", "sClass": "text-center"},
        {"mData": "provinceCode", "sClass": "text-center"},
        {"mData": "cityCode", "sClass": "text-center"},
        {"mData": "countyCode", "sClass": "text-center"},
        {"mData": "postcode", "sClass": "text-center"},
        {"mData": "street", "sClass": "text-center"},
        {"mData": "address", "sClass": "text-center"},
        {"mData": "bankName", "sClass": "text-center"},
        {"mData": "bankAccount", "sClass": "text-center"},
        {"mData": "remark", "sClass": "text-center"},
    ];
    var oTable1 = TableManaged(json).init();
}
/*查询数据*/
function doQuery(){
    initTable();
}


/*重置查询条件*/
function resetQueryForm(){
	$("#id").val('');
	$("#companyCode").val('');
	$("#companyName").val('');
	$("#companyType").val('');
	$("#companyShortName").val('');
	$("#companyProp").val('');
	$("#parentId").val('');
	$("#companyIndustry").val('');
	$("#licenseNo").val('');
	$("#licenseNoImg").val('');
	$("#taxNo").val('');
	$("#ajCompanyClass").val('');
	$("#corporation").val('');
	$("#ceo").val('');
	$("#ceoIdcard").val('');
	$("#ceoMobile").val('');
	$("#ceoIdcardAttachA").val('');
	$("#ceoIdcardAttachB").val('');
	$("#certificateStatus").val('');
	$("#certificateTime").val('');
	$("#certificatedTime").val('');
	$("#status").val('');
	$("#countryCode").val('');
	$("#provinceCode").val('');
	$("#cityCode").val('');
	$("#countyCode").val('');
	$("#postcode").val('');
	$("#street").val('');
	$("#address").val('');
	$("#bankName").val('');
	$("#bankAccount").val('');
	$("#remark").val('');
}

/*删除数据*/
function deleteCompany(companyCode){
    var _url=getBasePath()+'/mdm/company/delete.json';
    $.Confirm('你确定要删除这条记录吗？','',function(){
        var company={};
        company.companyCode=companyCode;
        $.ajax({
            url:_url,
            type:'POST',
            dataType:'json',
            contentType:'application/json',
            data:JSON.stringify(company),
            success:function(data){
                if(data.status==200){
                    $.Success('删除成功',doQuery);
                }else{
                    var msg = data.message || "删除公司数据发生错误";
                    $.Error(msg,'',null);
                }
            }
        });
    });

}

/*跳转编辑数据页面*/
function toEditCompany(companyCode){
    var _url=getBasePath()+'/mdm/company/toEdit.htm?companyCode='+companyCode;
    location.href=_url;
}

/*编辑数据*/
function editCompany(){
    $validator =$("#company_edit_form").validator('isFormValid');
    if(!$validator){
        return;
    }
    var _url=getBasePath()+'/mdm/company/edit.json';
    var company={};
	company.id=$("#id").val();
	company.companyCode=$("#companyCode").val();
	company.companyName=$("#companyName").val();
	company.companyType=$("#companyType").val();
	company.companyShortName=$("#companyShortName").val();
	company.companyProp=$("#companyProp").val();
	company.parentId=$("#parentId").val();
	company.companyIndustry=$("#companyIndustry").val();
	company.licenseNo=$("#licenseNo").val();
	company.licenseNoImg=$("#licenseNoImg").val();
	company.taxNo=$("#taxNo").val();
	company.ajCompanyClass=$("#ajCompanyClass").val();
	company.corporation=$("#corporation").val();
	company.ceo=$("#ceo").val();
	company.ceoIdcard=$("#ceoIdcard").val();
	company.ceoMobile=$("#ceoMobile").val();
	company.ceoIdcardAttachA=$("#ceoIdcardAttachA").val();
	company.ceoIdcardAttachB=$("#ceoIdcardAttachB").val();
	company.certificateStatus=$("#certificateStatus").val();
	company.certificateTime=$("#certificateTime").val();
	company.certificatedTime=$("#certificatedTime").val();
	company.status=$("#status").val();
	company.countryCode=$("#countryCode").val();
	company.provinceCode=$("#provinceCode").val();
	company.cityCode=$("#cityCode").val();
	company.countyCode=$("#countyCode").val();
	company.postcode=$("#postcode").val();
	company.street=$("#street").val();
	company.address=$("#address").val();
	company.bankName=$("#bankName").val();
	company.bankAccount=$("#bankAccount").val();
	company.remark=$("#remark").val();

    $.ajax({
        url:_url,
        type:'POST',
        dataType:'json',
        contentType:'application/json',
        data:JSON.stringify(company),
        success:function(data){
            if(data.status==200){
                $.Success('该记录已提交成功!',gotoListPage);
            }else{
                var msg = data.message || "编辑公司数据发生错误";
                $.Error(msg,'',null);
            }

        },
        error:function(data){
            JSON.stringify(data);
        }
    });
}

/* 跳转明细页面*/
function toDetailPage(code){
    var _url=getBasePath()+'/mdm/company/detail.htm?companyCode='+code;
    location.href=_url;
}
/*跳转新增数据页面*/
function toAddCompany(){
    var _url=getBasePath()+'/mdm/company/toAdd.htm';
    location.href=_url;
}

/*新增数据*/
function saveCompany(){
    $validator =$("#company_add_form").validator('isFormValid');
    if(!$validator){
        return;
    }
    var _url=getBasePath()+'/mdm/company/add.json';
    var company={};
	company.id=$("#id").val();
	company.companyCode=$("#companyCode").val();
	company.companyName=$("#companyName").val();
	company.companyType=$("#companyType").val();
	company.companyShortName=$("#companyShortName").val();
	company.companyProp=$("#companyProp").val();
	company.parentId=$("#parentId").val();
	company.companyIndustry=$("#companyIndustry").val();
	company.licenseNo=$("#licenseNo").val();
	company.licenseNoImg=$("#licenseNoImg").val();
	company.taxNo=$("#taxNo").val();
	company.ajCompanyClass=$("#ajCompanyClass").val();
	company.corporation=$("#corporation").val();
	company.ceo=$("#ceo").val();
	company.ceoIdcard=$("#ceoIdcard").val();
	company.ceoMobile=$("#ceoMobile").val();
	company.ceoIdcardAttachA=$("#ceoIdcardAttachA").val();
	company.ceoIdcardAttachB=$("#ceoIdcardAttachB").val();
	company.certificateStatus=$("#certificateStatus").val();
	company.certificateTime=$("#certificateTime").val();
	company.certificatedTime=$("#certificatedTime").val();
	company.status=$("#status").val();
	company.countryCode=$("#countryCode").val();
	company.provinceCode=$("#provinceCode").val();
	company.cityCode=$("#cityCode").val();
	company.countyCode=$("#countyCode").val();
	company.postcode=$("#postcode").val();
	company.street=$("#street").val();
	company.address=$("#address").val();
	company.bankName=$("#bankName").val();
	company.bankAccount=$("#bankAccount").val();
	company.remark=$("#remark").val();
    
    $.ajax({
        url:_url,
        type:'POST',
        dataType:'json',
        contentType:'application/json',
        data:JSON.stringify(company),
        success:function(data){
            if(data.status==200){
                $.Success('该记录已提交成功!',gotoListPage);
            }else{
                var msg = data.message || "新增公司数据发生错误";
                $.Error(msg,'',null);
            }
        }
    });
}

/*跳转数据列表页面*/
function gotoListPage(){
    location.href=getBasePath()+'/mdm/company/list.htm';
}





